import java.util.Map;

import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Registration;

public class Input {
	public InputListener inputListener;
	public Output o;
	public XMPPConnection myConnection;

	public Input(Output arg) {
		o = arg;
		this.myConnection = o.myConnection;
		inputListener = new InputListener(this);
		myConnection.addPacketListener(inputListener,
				new InputFilter());
	}
	
	public void processMessage(String arg1, String arg2){
		System.out.println("processing: " + arg1 + ", " + arg2);
		if(o.lobbyPanel != null)
			o.lobbyPanel.addLine(arg1, arg2);
	}
	
	public void ratingReset(Map<String, String> arg) {
		System.out.println("current keyset: " + arg.keySet());
		System.out.println("current info: " + arg);
		System.out.println("updating info...");
		
		o.myMap = arg;
		if (o.myMap.get("name") == null){
			System.out.println("name is null, set name to 800.");
			o.myMap.put("name", "800");
		}
		else{
			String s = o.myMap.get("name");
			if(s.substring(0, 1).equals("1"));
			else if(s.substring(0, 1).equals("8"));
			else if(s.substring(0, 1).equals("9"));
			else if(s.substring(0, 1).equals("7"));
			else if(s.substring(0, 1).equals("6"));
			else if(s.substring(0, 1).equals("5"));
			else if(s.substring(0, 1).equals("4"));
			else if(s.substring(0, 1).equals("3"));
			else if(s.substring(0, 1).equals("2"));
			else if(s.substring(0, 1).equals("0"));
			else{
				o.myMap.put("name", "800");
				System.out.println("name is not set to a number, set name to 800.");
			}
		}
		
		
		Registration rPacket = new Registration();
		rPacket.setAttributes(o.myMap);
		rPacket.setType(IQ.Type.SET);
		myConnection.sendPacket(rPacket);
		
		System.out.println("finished checking rating.");
	}
}
